home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Graphics Samples / Dashing Text ƒ / dashing text.c next >
Encoding:
C/C++ Source or Header  |  1995-04-10  |  4.0 KB  |  135 lines  |  [TEXT/KAHL]

  1. /*
  2.     dashing text.c 
  3.     
  4.     This file demonstrates dashing of text along a curve.
  5.     
  6.     NOTES:
  7.     • This file requires the following files to run correctly:
  8.         "graphics shell.c", "color library.c", "font library.c", "graphics debug library.c", "shape library.c",  
  9.         "transform library.c".
  10.         
  11.     • This file prints the "best" in landscape mode.
  12.       
  13.     ©1990 -1994  Apple Computer, Inc.
  14.     All rights reserved.
  15. */
  16.  
  17.  
  18. #include <events.h>
  19. #include <windows.h>
  20.  
  21. #include "font library.h"
  22. #include "graphics libraries.h"
  23. #include "graphics toolbox.h"
  24. #include "graphics shell.h"
  25.  
  26. //
  27. //  Set up the title and size of the window 
  28. //
  29. Str255         gWindowTitle = "\p Dashing text";
  30. Rect         gWindowQDRect  = {50, 50, 240, 495};
  31.  
  32. //
  33. //    gGraphicsHeapSize sets the size of the graphics heap created by calling the GXNewGraphicsClient routine
  34. //    in main () within graphics shell.c.  You can determine the amount of graphics heap required by using GraphicsBug.
  35. //    With gGraphicsHeapSize set to 105k, I had 3 free blocks left in the graphics heap. Sounds good to me.
  36. //
  37. long        gGraphicsHeapSize = 105;
  38.  
  39. gxShape     gDashingShape;
  40.  
  41.  
  42. /*------ DoInitialization ---------------------------------------------------------------------------------*/
  43.  
  44. void DoInitialization(aWindow)
  45. WindowPtr aWindow;
  46. {
  47.     gxCurve         curvepts = {{ff(10),ff(100)},{ff(150), -ff(55)},{ff(410),ff(150)}};
  48.     gxDashRecord    textDash;
  49.  
  50.      InitCommonColors();
  51.     
  52.     //  
  53.     //     Create the text shape that will be dashed
  54.      //  
  55.     textDash.dash = GXNewText(22,(unsigned char*)"QuickDraw™ GX is here!",  nil);
  56.     SetShapeCommonFont(textDash.dash, timesFont);
  57.     GXSetShapeTextSize(textDash.dash, ff(35));
  58.  
  59.     //  
  60.     // Set up the dash record.  Things to note: 
  61.     //        • scale should equal the text size. This will make sure that the text is dashed to the size of the curve
  62.     //        • If you want the textDash to be only used once on the curve, the advance must be larger than the curve's
  63.     //           length. You could use GXGetShapeLength (gDashingShape, ...); to determine the length of the curve and use this
  64.     //           value for advance.
  65.     //  
  66.     textDash.attributes = gxBreakDash | gxAutoAdvanceDash;
  67.     textDash.advance = ff(330);
  68.      textDash.phase = 0;
  69.     textDash.scale = ff(35);
  70.  
  71.     GXSetShapeType(textDash.dash, gxPathType);
  72.      
  73.     //  
  74.      //     Create the gxCurve to be dashed to.
  75.     //  
  76.       gDashingShape = GXNewCurve(&curvepts);
  77.       GXSetShapePen(gDashingShape, ff(35));
  78.     SetShapeCommonColor (gDashingShape, blue);
  79.     
  80.     //  
  81.     //     Add the textDash to the style of the gDashingShape. Since, we are adjusting the gxStyle of our shape and
  82.     //    this shape currently references the "default" style, GX graphics will make a copy of the style
  83.     //    and attach it to our shape.
  84.     //  
  85.     GXMoveShapeTo (gDashingShape, ff(30), ff(130));
  86.     GXSetShapeDash (gDashingShape, &textDash);
  87.     GXDisposeShape(textDash.dash);  
  88.   }
  89.  
  90.  
  91. /*------ DoDraw ---------------------------------------------------------------------------------------*/
  92.  
  93. void DoDraw(aWindow)
  94. WindowPtr aWindow;
  95. {
  96.     GXDrawShape (gDashingShape);
  97. }
  98.  
  99.  
  100. /*------ DoDispose -------------------------------------------------------------------------------------*/
  101.  
  102. void DoDispose(aWindow)
  103. WindowPtr aWindow;
  104. {
  105.     //  
  106.     //    You should always dispose of your GX graphics objects before tossing your window. Why? It's generally good 
  107.     //    form and this approach guarantees that everything is disposed. If you had not disposed of everything, the
  108.     //    call to DisposeWindow should dispose of the objects. If you are running the debugging version of the 
  109.     //    SecretGraphics init with notices set, you will receive a notice that you had not disposed of everything. You
  110.     //    can turn notices on in this file by setting gDebugging = TRUE (above).
  111.     //  
  112.     GXDisposeShape(gDashingShape);  
  113.      GXDisposeShape(gWindowBoundsShape);  
  114.        DisposeCommonColors();
  115.        DisposeWindow(aWindow);
  116. }
  117.     
  118.  
  119.  
  120. /*------ DoClick ---------------------------------------------------------------------------------------*/
  121.  
  122. void DoClick( orgMouseLoc, theWindow )
  123. gxPoint        orgMouseLoc;
  124. WindowPtr     theWindow;
  125. {
  126. }
  127.  
  128.  
  129. /*------ DoIdle ----------------------------------------------------------------------------------------*/
  130.  
  131. void DoIdle(aWindow)
  132. WindowPtr aWindow;
  133. {
  134. }
  135.